<template>
  <div class="footer-editor">
    <el-form :model="localConfig" label-width="100px" size="small">
      <!-- 左侧文本 -->
      <el-form-item label="左侧文本">
        <el-input
          v-model="localConfig.leftText"
          type="textarea"
          :rows="2"
          placeholder="请输入左侧文本，支持多行"
        />
      </el-form-item>

      <!-- 中间文本 -->
      <el-form-item label="中间文本">
        <el-input
          v-model="localConfig.centerText"
          type="textarea"
          :rows="2"
          placeholder="请输入中间文本，支持多行"
        />
      </el-form-item>

      <!-- 右侧文本 -->
      <el-form-item label="右侧文本">
        <el-input
          v-model="localConfig.rightText"
          type="textarea"
          :rows="2"
          placeholder="请输入右侧文本，支持多行"
        />
      </el-form-item>

      <!-- 签名行 -->
      <el-form-item label="签名区域">
        <el-button type="primary" size="mini" @click="addSignatureLine">添加签名行</el-button>
        <div v-for="(line, index) in localConfig.signatureLines" :key="index" class="signature-line">
          <el-input
            v-model="line.label"
            placeholder="标签"
            style="width: 120px; margin-right: 10px;"
          />
          <el-input
            v-model="line.value"
            placeholder="值"
            style="width: 150px; margin-right: 10px;"
          />
          <el-button size="mini" type="danger" @click="removeSignatureLine(index)">删除</el-button>
        </div>
      </el-form-item>

      <!-- 页脚信息 -->
      <el-form-item label="页脚信息">
        <el-input v-model="localConfig.footerInfo" placeholder="请输入页脚信息" />
      </el-form-item>

      <!-- 显示设置 -->
      <el-form-item label="显示设置">
        <el-checkbox v-model="localConfig.showBorder">显示顶部边框</el-checkbox>
      </el-form-item>

      <!-- 背景色 -->
      <el-form-item label="背景颜色">
        <el-color-picker v-model="localConfig.backgroundColor" />
      </el-form-item>

      <!-- 字体大小 -->
      <el-form-item label="字体大小">
        <el-select v-model="localConfig.fontSize" placeholder="请选择字体大小">
          <el-option label="小" value="12px" />
          <el-option label="正常" value="14px" />
          <el-option label="大" value="16px" />
        </el-select>
      </el-form-item>
    </el-form>

    <div class="editor-actions">
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="save">保存</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'FooterEditor',
  props: {
    footerConfig: {
      type: Object,
      default: () => ({
        leftText: '',
        centerText: '',
        rightText: '',
        showBorder: true,
        signatureLines: [],
        footerInfo: '',
        backgroundColor: '#f8f9fa',
        fontSize: '12px'
      })
    }
  },
  data() {
    return {
      localConfig: JSON.parse(JSON.stringify(this.footerConfig))
    }
  },
  methods: {
    addSignatureLine() {
      console.log(this.localConfig)
      this.localConfig.signatureLines.push({
        label: '签名',
        value: ''
      })
    },
    
    removeSignatureLine(index) {
      this.localConfig.signatureLines.splice(index, 1)
    },
    
    save() {
      this.$emit('save', this.localConfig)
    },
    
    cancel() {
      this.$emit('cancel')
    }
  }
}
</script>

<style scoped>
.footer-editor {
  padding: 20px;
}

.signature-line {
  display: flex;
  align-items: center;
  margin: 10px 0;
  padding: 8px;
  border: 1px dashed #e6e8eb;
  border-radius: 4px;
}

.editor-actions {
  text-align: right;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid #e6e8eb;
}
</style>